# 1为ARJ 111架机，2为C919 104架机
import pandas as pd
# 打开文件
# path = r'E:\试飞数据\处理后ADS-B数据\20241014\ADSB2024-10-14(B001E).txt'
from pandas import DataFrame
# 设置读取和存储路径
file = '20241022'
## 111架机ADS-B数据
ADS_B_file_name1 = 'ADSB2024-10-21(B3328)'

#读取路径
path1 = r'E:\试飞数据\原始ADS-B数据' + '\\' + file + '\\' +ADS_B_file_name1 + '.xlsx'


# 读取数据
df1 = pd.read_excel(path1)

list1 = []

for i in range(df1.shape[0]):
    list1.append(df1['创建时间'][i][11:])

plane_info = ['纬度','经度','高度(M)','地速(KM/H)','航向']

df_rearrange1 = df1.reindex(columns = plane_info)

df_rearrange1.columns = ['latitude_1','longitude_1','altitude_1','ground_speed_1','magnetic_1']


df_rearrange1.insert(5, 'time', list1, allow_duplicates=False)



df_rearrange1['time'] = pd.to_datetime(df_rearrange1['time'], format="%H:%M:%S")

df_rearrange1 = df_rearrange1.drop_duplicates('time')

df_rearrange1 = df_rearrange1.set_index('time')

df_rearrange1 = df_rearrange1.resample('500ms', origin='start').interpolate(method='linear')

df_rearrange1.index = df_rearrange1.index.strftime("%H:%M:%S:%f")

path_out1 = r'E:\试飞数据\双机试飞数据'+ '\\'+ file + '\\' + ADS_B_file_name1+'修_2Hz.txt'

#输出到指定路径下
df_rearrange1.to_csv(path_out1, sep='\t')
